﻿''' <summary>
''' Provides extension methods to the <see cref="DateTime">DateTime</see> object.
''' </summary>
''' <revisions>
'''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
''' </revisions>
Public Module DateTimeExtensions

  ''' <summary>
  ''' Gets the first day of the week (Sunday) for the given date.
  ''' </summary>
  ''' <param name="value">The date to use for determining the first day of the week.</param>
  ''' <returns>The first day of the week for the given date.</returns>
  ''' <remarks>Assumes that Sunday is the first day of the week.</remarks>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to the first day (Sunday) of the current week.</para>
  '''   <code language="vb">
  '''     Dim dtFirstDayOfWeek As DateTime = Now.FirstDayOfWeek
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtFirstDayOfWeek = Now.FirstDayOfWeek;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function FirstDayOfWeek(ByVal value As DateTime) As DateTime

    ' Variable Declarations
    Dim dteReturnvalue As Date

    ' Determine the First day of the specified week
    Try
      Select Case value.DayOfWeek
        Case DayOfWeek.Sunday
          dteReturnvalue = value
        Case DayOfWeek.Monday
          dteReturnvalue = value.Subtract(New TimeSpan(1, 0, 0, 0))
        Case DayOfWeek.Tuesday
          dteReturnvalue = value.Subtract(New TimeSpan(2, 0, 0, 0))
        Case DayOfWeek.Wednesday
          dteReturnvalue = value.Subtract(New TimeSpan(3, 0, 0, 0))
        Case DayOfWeek.Thursday
          dteReturnvalue = value.Subtract(New TimeSpan(4, 0, 0, 0))
        Case DayOfWeek.Friday
          dteReturnvalue = value.Subtract(New TimeSpan(5, 0, 0, 0))
        Case DayOfWeek.Saturday
          dteReturnvalue = value.Subtract(New TimeSpan(6, 0, 0, 0))
      End Select
    Catch ex As Exception
      Throw
    End Try

    ' Return the results
    Return dteReturnvalue

  End Function

  ''' <summary>
  ''' Gets the <see cref="DateTime">DateTime</see> that represents the last day of the week (Saturday) for the given date.
  ''' </summary>
  ''' <param name="value">The value to evaluate.</param>
  ''' <returns>The <see cref="DateTime">DateTime</see> that represents the last day of the week (Saturday) for the given date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to the last day (Saturday) of the current week.</para>
  '''   <code language="vb">
  '''     Dim dtLastDayOfWeek As DateTime = Now.LastDayOfWeek
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtLastDayOfWeek = Now.LastDayOfWeek;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function LastDayOfWeek(ByVal value As DateTime) As DateTime

    ' Variable Declarations
    Dim dteReturnvalue As Date

    ' Determine the last day of the week
    Try
      Select Case value.DayOfWeek
        Case DayOfWeek.Sunday
          dteReturnvalue = value.Add(New TimeSpan(6, 0, 0, 0))
        Case DayOfWeek.Monday
          dteReturnvalue = value.Add(New TimeSpan(5, 0, 0, 0))
        Case DayOfWeek.Tuesday
          dteReturnvalue = value.Add(New TimeSpan(4, 0, 0, 0))
        Case DayOfWeek.Wednesday
          dteReturnvalue = value.Add(New TimeSpan(3, 0, 0, 0))
        Case DayOfWeek.Thursday
          dteReturnvalue = value.Add(New TimeSpan(2, 0, 0, 0))
        Case DayOfWeek.Friday
          dteReturnvalue = value.Add(New TimeSpan(1, 0, 0, 0))
        Case DayOfWeek.Saturday
          dteReturnvalue = value
      End Select
    Catch ex As Exception
      Throw
    End Try

    ' Return the results
    Return dteReturnvalue

  End Function

  ''' <summary>
  ''' Gets the first day in the month for the given date.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing the first day in the month for the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to the first day of the current month.</para>
  '''   <code language="vb">
  '''     Dim dtFirstDayOfWeek As DateTime = Now.FirstDayOfMonth
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtFirstDayOfWeek = Now.FirstDayOfMonth;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function FirstDayOfMonth(ByVal value As DateTime) As DateTime
    Return value.AddDays(1 - value.Day)
  End Function

  ''' <summary>
  ''' Gets the first instance of the specified day in the specified month.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <param name="dayOfWeek">The day of week to return.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing the specified first day of the week in the month for the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to the first Tuesday of the current month.</para>
  '''   <code language="vb">
  '''     Dim dtFirstTuesdayOfWeek As DateTime = Now.FirstDayOfMonth(DayOfWeek.Tuesday)
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtFirstTuesdayOfWeek = Now.FirstDayOfMonth(DayOfWeek.Tuesday);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function FirstDayOfMonth(ByVal value As DateTime, ByVal dayOfWeek As DayOfWeek) As DateTime
    Select Case value.FirstDayOfMonth.DayOfWeek
      Case System.DayOfWeek.Sunday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.FirstDayOfMonth
          Case System.DayOfWeek.Monday
            Return value.FirstDayOfMonth.AddDays(1)
          Case System.DayOfWeek.Tuesday
            Return value.FirstDayOfMonth.AddDays(2)
          Case System.DayOfWeek.Wednesday
            Return value.FirstDayOfMonth.AddDays(3)
          Case System.DayOfWeek.Thursday
            Return value.FirstDayOfMonth.AddDays(4)
          Case System.DayOfWeek.Friday
            Return value.FirstDayOfMonth.AddDays(5)
          Case System.DayOfWeek.Saturday
            Return value.FirstDayOfMonth.AddDays(6)
        End Select
      Case System.DayOfWeek.Monday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.FirstDayOfMonth.AddDays(6)
          Case System.DayOfWeek.Monday
            Return value.FirstDayOfMonth
          Case System.DayOfWeek.Tuesday
            Return value.FirstDayOfMonth.AddDays(1)
          Case System.DayOfWeek.Wednesday
            Return value.FirstDayOfMonth.AddDays(2)
          Case System.DayOfWeek.Thursday
            Return value.FirstDayOfMonth.AddDays(3)
          Case System.DayOfWeek.Friday
            Return value.FirstDayOfMonth.AddDays(4)
          Case System.DayOfWeek.Saturday
            Return value.FirstDayOfMonth.AddDays(5)
        End Select
      Case System.DayOfWeek.Tuesday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.FirstDayOfMonth.AddDays(5)
          Case System.DayOfWeek.Monday
            Return value.FirstDayOfMonth.AddDays(6)
          Case System.DayOfWeek.Tuesday
            Return value.FirstDayOfMonth
          Case System.DayOfWeek.Wednesday
            Return value.FirstDayOfMonth.AddDays(1)
          Case System.DayOfWeek.Thursday
            Return value.FirstDayOfMonth.AddDays(2)
          Case System.DayOfWeek.Friday
            Return value.FirstDayOfMonth.AddDays(3)
          Case System.DayOfWeek.Saturday
            Return value.FirstDayOfMonth.AddDays(4)
        End Select
      Case System.DayOfWeek.Wednesday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.FirstDayOfMonth.AddDays(4)
          Case System.DayOfWeek.Monday
            Return value.FirstDayOfMonth.AddDays(5)
          Case System.DayOfWeek.Tuesday
            Return value.FirstDayOfMonth.AddDays(6)
          Case System.DayOfWeek.Wednesday
            Return value.FirstDayOfMonth
          Case System.DayOfWeek.Thursday
            Return value.FirstDayOfMonth.AddDays(1)
          Case System.DayOfWeek.Friday
            Return value.FirstDayOfMonth.AddDays(2)
          Case System.DayOfWeek.Saturday
            Return value.FirstDayOfMonth.AddDays(3)
        End Select
      Case System.DayOfWeek.Thursday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.FirstDayOfMonth.AddDays(3)
          Case System.DayOfWeek.Monday
            Return value.FirstDayOfMonth.AddDays(4)
          Case System.DayOfWeek.Tuesday
            Return value.FirstDayOfMonth.AddDays(5)
          Case System.DayOfWeek.Wednesday
            Return value.FirstDayOfMonth.AddDays(6)
          Case System.DayOfWeek.Thursday
            Return value.FirstDayOfMonth
          Case System.DayOfWeek.Friday
            Return value.FirstDayOfMonth.AddDays(1)
          Case System.DayOfWeek.Saturday
            Return value.FirstDayOfMonth.AddDays(2)
        End Select
      Case System.DayOfWeek.Friday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.FirstDayOfMonth.AddDays(2)
          Case System.DayOfWeek.Monday
            Return value.FirstDayOfMonth.AddDays(3)
          Case System.DayOfWeek.Tuesday
            Return value.FirstDayOfMonth.AddDays(4)
          Case System.DayOfWeek.Wednesday
            Return value.FirstDayOfMonth.AddDays(5)
          Case System.DayOfWeek.Thursday
            Return value.FirstDayOfMonth.AddDays(6)
          Case System.DayOfWeek.Friday
            Return value.FirstDayOfMonth
          Case System.DayOfWeek.Saturday
            Return value.FirstDayOfMonth.AddDays(1)
        End Select
      Case System.DayOfWeek.Saturday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.FirstDayOfMonth.AddDays(1)
          Case System.DayOfWeek.Monday
            Return value.FirstDayOfMonth.AddDays(2)
          Case System.DayOfWeek.Tuesday
            Return value.FirstDayOfMonth.AddDays(3)
          Case System.DayOfWeek.Wednesday
            Return value.FirstDayOfMonth.AddDays(4)
          Case System.DayOfWeek.Thursday
            Return value.FirstDayOfMonth.AddDays(5)
          Case System.DayOfWeek.Friday
            Return value.FirstDayOfMonth.AddDays(6)
          Case System.DayOfWeek.Saturday
            Return value.FirstDayOfMonth
        End Select
    End Select
  End Function

  ''' <summary>
  ''' Gets the last day in the month for the given date.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing the last day in the month for the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to the last day of the current month.</para>
  '''   <code language="vb">
  '''     Dim dtLastDayOfMonth As DateTime = Now.LastDayOfMonth
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtLastDayOfMonth = Now.LastDayOfMonth();
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function LastDayOfMonth(ByVal value As DateTime) As DateTime
    Return value.FirstDayOfMonth().AddDays((DateTime.DaysInMonth(value.Year, value.Month)) - 1)
  End Function

  ''' <summary>
  ''' Gets the last specified day of the week in the month for the given date.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <param name="dayOfWeek">The day of week to return.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing the specified last day of the week in the month for the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to the last Tuesday of the current month.</para>
  '''   <code language="vb">
  '''     Dim dtLastTuesdayOfWeek As DateTime = Now.LastDayOfMonth(DayOfWeek.Tuesday)
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtLastTuesdayOfWeek = Now.LastDayOfMonth(DayOfWeek.Tuesday);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function LastDayOfMonth(ByVal value As DateTime, ByVal dayOfWeek As DayOfWeek) As DateTime
    Select Case value.LastDayOfMonth.DayOfWeek
      Case System.DayOfWeek.Sunday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.LastDayOfMonth
          Case System.DayOfWeek.Monday
            Return value.LastDayOfMonth.AddDays(-6)
          Case System.DayOfWeek.Tuesday
            Return value.LastDayOfMonth.AddDays(-5)
          Case System.DayOfWeek.Wednesday
            Return value.LastDayOfMonth.AddDays(-4)
          Case System.DayOfWeek.Thursday
            Return value.LastDayOfMonth.AddDays(-3)
          Case System.DayOfWeek.Friday
            Return value.LastDayOfMonth.AddDays(-2)
          Case System.DayOfWeek.Saturday
            Return value.LastDayOfMonth.AddDays(-1)
        End Select
      Case System.DayOfWeek.Monday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.LastDayOfMonth.AddDays(-1)
          Case System.DayOfWeek.Monday
            Return value.LastDayOfMonth
          Case System.DayOfWeek.Tuesday
            Return value.LastDayOfMonth.AddDays(-6)
          Case System.DayOfWeek.Wednesday
            Return value.LastDayOfMonth.AddDays(-5)
          Case System.DayOfWeek.Thursday
            Return value.LastDayOfMonth.AddDays(-4)
          Case System.DayOfWeek.Friday
            Return value.LastDayOfMonth.AddDays(-3)
          Case System.DayOfWeek.Saturday
            Return value.LastDayOfMonth.AddDays(-2)
        End Select
      Case System.DayOfWeek.Tuesday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.LastDayOfMonth.AddDays(-2)
          Case System.DayOfWeek.Monday
            Return value.LastDayOfMonth.AddDays(-1)
          Case System.DayOfWeek.Tuesday
            Return value.LastDayOfMonth
          Case System.DayOfWeek.Wednesday
            Return value.LastDayOfMonth.AddDays(-6)
          Case System.DayOfWeek.Thursday
            Return value.LastDayOfMonth.AddDays(-5)
          Case System.DayOfWeek.Friday
            Return value.LastDayOfMonth.AddDays(-4)
          Case System.DayOfWeek.Saturday
            Return value.LastDayOfMonth.AddDays(-3)
        End Select
      Case System.DayOfWeek.Wednesday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.LastDayOfMonth.AddDays(-3)
          Case System.DayOfWeek.Monday
            Return value.LastDayOfMonth.AddDays(-2)
          Case System.DayOfWeek.Tuesday
            Return value.LastDayOfMonth.AddDays(-1)
          Case System.DayOfWeek.Wednesday
            Return value.LastDayOfMonth
          Case System.DayOfWeek.Thursday
            Return value.LastDayOfMonth.AddDays(-6)
          Case System.DayOfWeek.Friday
            Return value.LastDayOfMonth.AddDays(-5)
          Case System.DayOfWeek.Saturday
            Return value.LastDayOfMonth.AddDays(-4)
        End Select
      Case System.DayOfWeek.Thursday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.LastDayOfMonth.AddDays(-4)
          Case System.DayOfWeek.Monday
            Return value.LastDayOfMonth.AddDays(-3)
          Case System.DayOfWeek.Tuesday
            Return value.LastDayOfMonth.AddDays(-2)
          Case System.DayOfWeek.Wednesday
            Return value.LastDayOfMonth.AddDays(-1)
          Case System.DayOfWeek.Thursday
            Return value.LastDayOfMonth
          Case System.DayOfWeek.Friday
            Return value.LastDayOfMonth.AddDays(-6)
          Case System.DayOfWeek.Saturday
            Return value.LastDayOfMonth.AddDays(-5)
        End Select
      Case System.DayOfWeek.Friday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.LastDayOfMonth.AddDays(-5)
          Case System.DayOfWeek.Monday
            Return value.LastDayOfMonth.AddDays(-4)
          Case System.DayOfWeek.Tuesday
            Return value.LastDayOfMonth.AddDays(-3)
          Case System.DayOfWeek.Wednesday
            Return value.LastDayOfMonth.AddDays(-2)
          Case System.DayOfWeek.Thursday
            Return value.LastDayOfMonth.AddDays(-1)
          Case System.DayOfWeek.Friday
            Return value.LastDayOfMonth
          Case System.DayOfWeek.Saturday
            Return value.LastDayOfMonth.AddDays(-6)
        End Select
      Case System.DayOfWeek.Saturday
        Select Case dayOfWeek
          Case System.DayOfWeek.Sunday
            Return value.LastDayOfMonth.AddDays(-6)
          Case System.DayOfWeek.Monday
            Return value.LastDayOfMonth.AddDays(-5)
          Case System.DayOfWeek.Tuesday
            Return value.LastDayOfMonth.AddDays(-4)
          Case System.DayOfWeek.Wednesday
            Return value.LastDayOfMonth.AddDays(-3)
          Case System.DayOfWeek.Thursday
            Return value.LastDayOfMonth.AddDays(-2)
          Case System.DayOfWeek.Friday
            Return value.LastDayOfMonth.AddDays(-1)
          Case System.DayOfWeek.Saturday
            Return value.LastDayOfMonth
        End Select
    End Select
  End Function

  ''' <summary>
  ''' Gets the first date following the specified date which falls on the specified day of the week.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <param name="dayOfWeek">The day of week to return.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing the next specified day of week that falls after after the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to the next Monday in the current month.</para>
  '''   <code language="vb">
  '''     Dim dtNextMonday As DateTime = Now.NextDayofMonth(DayOfWeek.Monday)
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtNextMonday = Now.NextDayofMonth(DayOfWeek.Monday);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function NextDayofMonth(ByVal value As DateTime, ByVal dayOfWeek As DayOfWeek) As DateTime
    Dim intOffsetDays As Integer = dayOfWeek - value.DayOfWeek
    If intOffsetDays <= 0 Then intOffsetDays += 7
    Return value.AddDays(intOffsetDays)
  End Function

  ''' <summary>
  ''' Gets a <see cref="DateTime">DateTime</see> representing midnight on the specified date.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing midnight on the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to the first day of the current month at midnight.</para>
  '''   <code language="vb">
  '''     Dim dtMidnight As DateTime = Now.FirstDayOfMonth.Midnight
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtMidnight = Now.FirstDayOfMonth.Midnight;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function Midnight(ByVal value As DateTime) As DateTime
    Return New DateTime(value.Year, value.Month, value.Day)
  End Function

  ''' <summary>
  ''' Gets a <see cref="DateTime">DateTime</see> representing 23:59:59 on the specified date.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing 23:59:59 on the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to the last day of the current month at 23:59.59.</para>
  '''   <code language="vb">
  '''     Dim dtMidnight As DateTime = Now.LastDayOfMonth.Midnight
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtMidnight = Now.LastDayOfMonth.Midnight;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function EndOfDay(ByVal value As DateTime) As DateTime
    Return New DateTime(value.Year, value.Month, value.Day, 23, 59, 59)
  End Function

  ''' <summary>
  ''' Gets a <see cref="DateTime">DateTime</see> representing noon on the specified date.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing noon on the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to the noon (12:00:00) of the current day.</para>
  '''   <code language="vb">
  '''     Dim dtMidnight As DateTime = Now.Noon
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtMidnight = Now.Noon;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function Noon(ByVal value As DateTime) As DateTime
    Return New DateTime(value.Year, value.Month, value.Day, 12, 0, 0)
  End Function

  ''' <summary>
  ''' Sets the time of the specified date with minute precision.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <param name="hour">The hour to set the return value to.</param>
  ''' <returns>The specified date set to hour precision.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to 15:00:00.000 of the current day.</para>
  '''   <code language="vb">
  '''     Dim dtRunTime As DateTime = Now.SetTime(15)
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtRunTime = Now.SetTime(15);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function SetTime(ByVal value As DateTime, _
                                        ByVal hour As Integer) As DateTime
    Return SetTime(value, hour, 0)
  End Function

  ''' <summary>
  ''' Sets the time of the specified date with minute precision.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <param name="hour">The hour to set the return value to.</param>
  ''' <param name="minute">The minute to set the return value to.</param>
  ''' <returns>The specified date set to minute precision.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to 15:05:00.000 of the current day.</para>
  '''   <code language="vb">
  '''     Dim dtRunTime As DateTime = Now.SetTime(15, 5)
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtRunTime = Now.SetTime(15, 5);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function SetTime(ByVal value As DateTime, _
                                        ByVal hour As Integer, _
                                        ByVal minute As Integer) As DateTime
    Return SetTime(value, hour, minute, 0, 0)
  End Function

  ''' <summary>
  ''' Sets the time of the specified date with second precision.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <param name="hour">The hour to set the return value to.</param>
  ''' <param name="minute">The minute to set the return value to.</param>
  ''' <param name="second">The second to set the return value to.</param>
  ''' <returns>The specified date set to second precision.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to 15:05:30.000 of the current day.</para>
  '''   <code language="vb">
  '''     Dim dtRunTime As DateTime = Now.SetTime(15, 5, 30)
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtRunTime = Now.SetTime(15, 5, 30);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function SetTime(ByVal value As DateTime, _
                                        ByVal hour As Integer, _
                                        ByVal minute As Integer, _
                                        ByVal second As Integer) As DateTime
    Return SetTime(value, hour, minute, second, 0)
  End Function

  ''' <summary>
  ''' Sets the time of the specified date with millisecond precision.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <param name="hour">The hour to set the return value to.</param>
  ''' <param name="minute">The minute to set the return value to.</param>
  ''' <param name="second">The second to set the return value to.</param>
  ''' <param name="millisecond">The millisecond to set the return value to.</param>
  ''' <returns>The specified date set to millisecond precision.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to 15:05:30.500 of the current day.</para>
  '''   <code language="vb">
  '''     Dim dtRunTime As DateTime = Now.SetTime(15, 5, 30, 500)
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtRunTime = Now.SetTime(15, 5, 30, 500);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function SetTime(ByVal value As DateTime, _
                                        ByVal hour As Integer, _
                                        ByVal minute As Integer, _
                                        ByVal second As Integer, _
                                        ByVal millisecond As Integer) As DateTime
    Return New DateTime(value.Year, value.Month, value.Day, hour, minute, second, millisecond)
  End Function

  ''' <summary>
  ''' Subtracts one month from the specified date.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing one month previous of the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to one month ago from today.</para>
  '''   <code language="vb">
  '''     Dim dtLastMonth As DateTime = Now.SubtractMonth
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtLastMonth = Now.SubtractMonth;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function SubtractMonth(ByVal value As DateTime) As DateTime
    Select Case value.Month
      Case 1
        Return DateSerial(value.Year - 1, 12, value.Day)
      Case 2, 6, 8, 9, 11
        Return DateSerial(value.Year, value.Month - 1, value.Day)
      Case 3
        If value.IsLeapYear = True And value.Day > 29 Then
          Return DateSerial(value.Year, 2, 29)
        ElseIf value.Day > 28 Then
          Return DateSerial(value.Year, 2, 28)
        Else
          Return DateSerial(value.Year, 2, value.Day)
        End If
      Case 4
        Return DateSerial(value.Year, value.Month - 1, value.Day)
      Case 5, 7, 10, 12
        If value.Day > 30 Then
          Return DateSerial(value.Year, value.Month - 1, 30)
        Else
          Return DateSerial(value.Year, value.Month - 1, value.Day)
        End If
    End Select
  End Function

  ''' <summary>
  ''' Adds one month to the specified date.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing one month after of the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to one month from today.</para>
  '''   <code language="vb">
  '''     Dim dtAddMonth As DateTime = Now.AddMonth
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtAddMonth = Now.AddMonth;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function AddMonth(ByVal value As DateTime) As DateTime
    Select Case value.Month
      Case 1
        If value.IsLeapYear = True And value.Day > 29 Then
          Return DateSerial(value.Year, 2, 29)
        ElseIf value.Day > 28 Then
          Return DateSerial(value.Year, 2, 28)
        Else
          Return DateSerial(value.Year, 2, value.Day)
        End If
      Case 2
        Return DateSerial(value.Year, 3, value.Day)
      Case 3, 5, 8, 10
        If value.Day > 30 Then
          Return DateSerial(value.Year, value.Month + 1, 30)
        Else
          Return DateSerial(value.Year, value.Month + 1, value.Day)
        End If
      Case 4, 6, 7, 9, 11
        Return DateSerial(value.Year, value.Month + 1, value.Day)
      Case 12
        Return DateSerial(value.Year + 1, 1, value.Day)
    End Select
  End Function

  ''' <summary>
  ''' Determines whether the specified <see cref="DateTime">DateTime</see> is in a leap year.
  ''' </summary>
  ''' <param name="value">The value.</param>
  ''' <returns><c>true</c> if the specified value is in a leap year; otherwise, <c>false</c>.</returns>
  ''' <example>
  '''   <para>The following examples get a indications as to whether the specified years are leap years.</para>
  '''   <code language="vb">
  '''     Dim bIs2008ALeapYear As Boolean = New DateTime(2008, 1, 1).IsLeapYear  ' Will return True
  '''     Dim bIs1995ALeapYear As Boolean = New DateTime(1995, 1, 1).IsLeapYear  ' Will return False
  '''   </code>
  '''   <code language="c#">
  '''     // Will return True
  '''     bool bIs2008ALeapYear = new DateTime(2008, 1, 1).IsLeapYear;
  '''     // Will return False
  '''     bool bIs2008ALeapYear = new DateTime(1995, 1, 1).IsLeapYear;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function IsLeapYear(ByVal value As DateTime) As Boolean
    Return Date.IsLeapYear(value.Year)
  End Function

  ''' <summary>
  ''' Subtracts one week from the specified <see cref="DateTime">DateTime</see> value.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing one weeek from the specified <see cref="DateTime">DateTime</see>.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to one week ago from today.</para>
  '''   <code language="vb">
  '''     Dim dtSubtractWeek As DateTime = Now.SubtractWeek
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtSubtractWeek = Now.SubtractWeek;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function SubtractWeek(ByVal value As DateTime) As DateTime
    Return value.SubtractWeek(1)
  End Function

  ''' <summary>
  ''' Subtracts the specified number of weeks from the specified <see cref="DateTime">DateTime</see> value.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <param name="numberOfWeeks">The number of weeks to subtract from the specified value.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing the specified number of weeks from the specified <see cref="DateTime">DateTime</see>.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to two week ago from today.</para>
  '''   <code language="vb">
  '''     Dim dtSubtractTwoWeeks As DateTime = Now.SubtractWeek(2)
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtSubtractTwoWeeks = Now.SubtractWeek(2);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function SubtractWeek(ByVal value As DateTime, _
                               ByVal numberOfWeeks As Integer) As DateTime
    Return value.Subtract(New TimeSpan(7 * numberOfWeeks, 0, 0, 0))
  End Function

  ''' <summary>
  ''' Adds one week to the specified <see cref="DateTime">DateTime</see> value.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing one weeek after the specified <see cref="DateTime">DateTime</see>.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to one week from today.</para>
  '''   <code language="vb">
  '''     Dim dtOneWeekFromToday As DateTime = Now.AddWeek
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtOneWeekFromToday = Now.AddWeek();
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function AddWeek(ByVal value As DateTime) As DateTime
    Return value.AddWeek(1)
  End Function

  ''' <summary>
  ''' Adds the specified number of weeks to the specified <see cref="DateTime">DateTime</see> value.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <param name="numberOfWeeks">The number of weeks to add to the specified value.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> representing the specified number of weeks after the specified <see cref="DateTime">DateTime</see>.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to three weeks from today.</para>
  '''   <code language="vb">
  '''     Dim dtThreeWeekFromToday As DateTime = Now.AddWeek(3)
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtThreeWeekFromToday = Now.AddWeek(3);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function AddWeek(ByVal value As DateTime, _
                          ByVal numberOfWeeks As Integer) As DateTime
    Return value.Add(New TimeSpan(7 * numberOfWeeks, 0, 0, 0))
  End Function

  ''' <summary>
  ''' Gets the julian date (as defined by DOD) for the specified date value.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>The julian date (as specified by DOD) for the specified date value.</returns>
  ''' <example>
  '''   <para>The following examples display a message box displaying the julian date (2008046) for February 15, 2008.</para>
  '''   <code language="vb">
  '''     MsgBox(New DateTime(2008, 2, 15).JulianDate)
  '''   </code>
  '''   <code language="c#">
  '''     MsgBox(new DateTime(2008, 2, 15).JulianDate);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function JulianDate(ByVal value As DateTime) As String
    Dim lngDateDiff As Long = DateDiff(DateInterval.Day, DateSerial(Year(value) - 1, 12, 31), value)
    If lngDateDiff < 10 Then
      Return Year(value).ToString(Globalization.CultureInfo.InvariantCulture) + "00" + lngDateDiff.ToString(Globalization.CultureInfo.InvariantCulture)
    ElseIf lngDateDiff < 100 Then
      Return Year(value).ToString(Globalization.CultureInfo.InvariantCulture) + "0" + lngDateDiff.ToString(Globalization.CultureInfo.InvariantCulture)
    Else
      Return Year(value).ToString(Globalization.CultureInfo.InvariantCulture) + lngDateDiff.ToString(Globalization.CultureInfo.InvariantCulture)
    End If
  End Function

  ''' <summary>
  ''' Gets the first day of the previous quarter.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>The first day of the previous government's fiscal quarter.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to first day of the previous quarter.  The result will be January 1, 2008.</para>
  '''   <code language="vb">
  '''     Dim dtFirstDayOfPreviousQuarter As DateTime = New DateTime(2008, 6, 21).FirstDayOfPreviousQuarter
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtFirstDayOfPreviousQuarter = new DateTime(2008, 6, 21).FirstDayOfPreviousQuarter;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function FirstDayOfPreviousQuarter(ByVal value As DateTime) As DateTime
    Select Case Month(value)
      Case 1 To 3
        Return New DateTime(value.Year - 1, 10, 1)
      Case 4 To 6
        Return New DateTime(value.Year, 1, 1)
      Case 7 To 9
        Return New DateTime(value.Year, 4, 1)
      Case 10 To 12
        Return New DateTime(value.Year, 7, 1)
    End Select
  End Function

  ''' <summary>
  ''' Gets the first day of the current quarter.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>The first day of the current quarter.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to first day of the current quarter.  The result will be April 1, 2008.</para>
  '''   <code language="vb">
  '''     Dim dtFirstDayOfCurrentQuarter As DateTime = New DateTime(2008, 6, 21).FirstDayOfCurrentQuarter
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtFirstDayOfCurrentQuarter = new DateTime(2008, 6, 21).FirstDayOfCurrentQuarter;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function FirstDayOfCurrentQuarter(ByVal value As DateTime) As DateTime
    Select Case Month(value)
      Case 1 To 3
        Return New DateTime(value.Year, 1, 1)
      Case 4 To 6
        Return New DateTime(value.Year, 4, 1)
      Case 7 To 9
        Return New DateTime(value.Year, 7, 1)
      Case 10 To 12
        Return New DateTime(value.Year, 10, 1)
    End Select
  End Function

  ''' <summary>
  ''' Gets the last day of the previous government's fiscal quarter.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>The last day of the previous government's fiscal quarter.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to first day of the current quarter.  The result will be June 30, 2008.</para>
  '''   <code language="vb">
  '''     Dim dtLastDayOfPreviousQuarter As DateTime = New DateTime(2008, 6, 21).LastDayOfPreviousQuarter
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtLastDayOfPreviousQuarter = new DateTime(2008, 6, 21).LastDayOfPreviousQuarter;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function LastDayOfPreviousQuarter(ByVal value As DateTime) As DateTime
    Select Case Month(value)
      Case 1 To 3
        Return New DateTime(value.Year - 1, 12, 31)
      Case 4 To 6
        Return New DateTime(value.Year, 3, 31)
      Case 7 To 9
        Return New DateTime(value.Year, 6, 30)
      Case 10 To 12
        Return New DateTime(value.Year, 9, 30)
    End Select
  End Function

  ''' <summary>
  ''' Gets a <see cref="DateTime">DateTime</see> that represents the current hour.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> that represents the current hour.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to hour of the specified date.  The result will be June 21, 2008 21:00:00.000.</para>
  '''   <code language="vb">
  '''     Dim dtToHour As DateTime = New DateTime(2008, 6, 21).ToHour
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtToHour = new DateTime(2008, 6, 21).ToHour;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function ToHour(ByVal value As DateTime) As DateTime
    Return value.SetTime(value.Hour)
  End Function

  ''' <summary>
  ''' Gets the government's fiscal year for the specified date.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <returns>The government's fiscal year.</returns>
  ''' <example>
  '''   <para>The following examples will display a message box displaying the fiscal year for the specified date.  The displayed value will be 2008.</para>
  '''   <code language="vb">
  '''     MsgBox(New DateTime(2008, 5, 21).FiscalYear)
  '''   </code>
  '''   <code language="c#">
  '''     MsgBox(new DateTime(2008, 5, 21).FiscalYear);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function FiscalYear(ByVal value As DateTime) As Short

    ' Variable Declarations
    Dim shtReturnvalue As Short

    ' Determine the fiscal year
    Try
      If value.Month > 9 Then
        shtReturnvalue = Convert.ToInt16(value.Year + 1)
      Else
        shtReturnvalue = Convert.ToInt16(value.Year)
      End If
    Catch ex As Exception
      Throw
    End Try

    ' Return The results
    Return shtReturnvalue

  End Function

  ''' <summary>
  ''' Gets a <see cref="DateTime">DateTime</see> object representing the first calendar day in the fiscal year for the specified date.
  ''' </summary>
  ''' <param name="value">The date to be evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> object representing the first calendar day in the fiscal year for the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to first calendar day of the current fiscal year.  The result will be October 1, 2007.</para>
  '''   <code language="vb">
  '''     Dim dtFirstCalendarDayOfCurrentFiscalYear As DateTime = New DateTime(2008, 6, 21).FirstCalendarDayOfCurrentFiscalYear
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtFirstCalendarDayOfCurrentFiscalYear = new DateTime(2008, 6, 21).FirstCalendarDayOfCurrentFiscalYear;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function FirstCalendarDayOfCurrentFiscalYear(ByVal value As DateTime) As DateTime
    Return DateSerial(value.FiscalYear - 1, 10, 1)
  End Function

  ''' <summary>
  ''' Gets a <see cref="DateTime">DateTime</see> object representing the first work day in the fiscal year for the specified date.
  ''' </summary>
  ''' <param name="value">The date to be evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> object representing the first work day in the fiscal year for the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to first work day (Monday through Friday) of the current fiscal year.  The result will be October 1, 2007.</para>
  '''   <code language="vb">
  '''     Dim dtFirstWorkDayOfCurrentFiscalYear As DateTime = New DateTime(2008, 6, 21).FirstWorkDayOfCurrentFiscalYear
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtFirstWorkDayOfCurrentFiscalYear = new DateTime(2008, 6, 21).FirstWorkDayOfCurrentFiscalYear;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function FirstWorkDayOfCurrentFiscalYear(ByVal value As DateTime) As DateTime
    Select Case value.FirstCalendarDayOfCurrentFiscalYear.DayOfWeek
      Case DayOfWeek.Sunday
        Return value.FirstCalendarDayOfCurrentFiscalYear.AddDays(1)
      Case DayOfWeek.Saturday
        Return value.FirstCalendarDayOfCurrentFiscalYear.AddDays(2)
      Case Else
        Return value.FirstCalendarDayOfCurrentFiscalYear
    End Select
  End Function

  ''' <summary>
  ''' Gets a <see cref="DateTime">DateTime</see> object representing the first calendar day in the previous fiscal year for the specified date.
  ''' </summary>
  ''' <param name="value">The date to be evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> object representing the first calendar day in the previous fiscal year for the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to first calendar day of the previous fiscal year.  The result will be October 1, 2006.</para>
  '''   <code language="vb">
  '''     Dim dtFirstCalendarDayOfPreviousFiscalYear As DateTime = New DateTime(2008, 6, 21).FirstCalendarDayOfPreviousFiscalYear
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtFirstCalendarDayOfPreviousFiscalYear = new DateTime(2008, 6, 21).FirstCalendarDayOfPreviousFiscalYear;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function FirstCalendarDayOfPreviousFiscalYear(ByVal value As DateTime) As DateTime
    If value.FiscalYear = Now.Year Then
      Return New DateTime(value.FiscalYear - 2, 10, 1)
    Else
      Return New DateTime(value.FiscalYear - 3, 10, 1)
    End If
  End Function

  ''' <summary>
  ''' Gets a <see cref="DateTime">DateTime</see> object representing the first work day in the previous fiscal year for the specified date.
  ''' </summary>
  ''' <param name="value">The date to be evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> object representing the first work day in the previous fiscal year for the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to first work day (Monday through Friday) of the previous fiscal year.  The result will be October 2, 2006.</para>
  '''   <code language="vb">
  '''     Dim dtFirstWorkDayOfPreviousFiscalYear As DateTime = New DateTime(2008, 6, 21).FirstWorkDayOfPreviousFiscalYear
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtFirstWorkDayOfPreviousFiscalYear = new DateTime(2008, 6, 21).FirstWorkDayOfPreviousFiscalYear;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function FirstWorkDayOfPreviousFiscalYear(ByVal value As DateTime) As DateTime
    Select Case value.FirstCalendarDayOfPreviousFiscalYear.DayOfWeek
      Case DayOfWeek.Sunday
        Return value.FirstCalendarDayOfPreviousFiscalYear.AddDays(1)
      Case DayOfWeek.Saturday
        Return value.FirstCalendarDayOfPreviousFiscalYear.AddDays(2)
      Case Else
        Return value.FirstCalendarDayOfPreviousFiscalYear
    End Select
  End Function

  ''' <summary>
  ''' Gets a <see cref="DateTime">DateTime</see> object representing the first calendar day in the fiscal year for the specified date.
  ''' </summary>
  ''' <param name="value">The date to be evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> object representing the first calendar day in the fiscal year for the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to last calendar day of the current fiscal year.  The result will be September 30, 2008.</para>
  '''   <code language="vb">
  '''     Dim dtLastCalendarDayOfCurrentFiscalYear As DateTime = New DateTime(2008, 6, 21).LastCalendarDayOfCurrentFiscalYear
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtLastCalendarDayOfCurrentFiscalYear = new DateTime(2008, 6, 21).LastCalendarDayOfCurrentFiscalYear;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function LastCalendarDayOfCurrentFiscalYear(ByVal value As DateTime) As DateTime
    Return DateSerial(value.FiscalYear, 9, Date.DaysInMonth(value.FiscalYear, 9))
  End Function

  ''' <summary>
  ''' Gets a <see cref="DateTime">DateTime</see> object representing the first work day in the fiscal year for the specified date.
  ''' </summary>
  ''' <param name="value">The date to be evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> object representing the first work day in the fiscal year for the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to first calendar day of the previous fiscal year.  The result will be September 30, 2008.</para>
  '''   <code language="vb">
  '''     Dim dtLastWorkDayOfCurrentFiscalYear As DateTime = New DateTime(2008, 6, 21).LastWorkDayOfCurrentFiscalYear
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtLastWorkDayOfCurrentFiscalYear = new DateTime(2008, 6, 21).LastWorkDayOfCurrentFiscalYear;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function LastWorkDayOfCurrentFiscalYear(ByVal value As DateTime) As DateTime
    Select Case value.LastCalendarDayOfCurrentFiscalYear.DayOfWeek
      Case DayOfWeek.Sunday
        Return value.LastCalendarDayOfCurrentFiscalYear.Subtract(New TimeSpan(2, 0, 0, 0))
      Case DayOfWeek.Saturday
        Return value.LastCalendarDayOfCurrentFiscalYear.Subtract(New TimeSpan(1, 0, 0, 0))
      Case Else
        Return value.LastCalendarDayOfCurrentFiscalYear
    End Select
  End Function

  ''' <summary>
  ''' Gets a <see cref="DateTime">DateTime</see> object representing the first calendar day in the previous fiscal year for the specified date.
  ''' </summary>
  ''' <param name="value">The date to be evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> object representing the last calendar day in the previous fiscal year for the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to last calendar day of the previous fiscal year.  The result will be September 30, 2006.</para>
  '''   <code language="vb">
  '''     Dim dtLastCalendarDayOfPreviousFiscalYear As DateTime = New DateTime(2008, 6, 21).LastCalendarDayOfPreviousFiscalYear
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtLastCalendarDayOfPreviousFiscalYear = new DateTime(2008, 6, 21).LastCalendarDayOfPreviousFiscalYear;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function LastCalendarDayOfPreviousFiscalYear(ByVal value As DateTime) As DateTime
    Return DateSerial(value.FiscalYear - 1, 9, Date.DaysInMonth(value.FiscalYear - 1, 9))
  End Function

  ''' <summary>
  ''' Gets a <see cref="DateTime">DateTime</see> object representing the first work day in the previous fiscal year for the specified date.
  ''' </summary>
  ''' <param name="value">The date to be evaluate.</param>
  ''' <returns>A <see cref="DateTime">DateTime</see> object representing the last work day in the previous fiscal year for the specified date.</returns>
  ''' <example>
  '''   <para>The following examples get a DateTime value equal to last work day (Monday through Friday) of the previous fiscal year.  The result will be September 29, 2006.</para>
  '''   <code language="vb">
  '''     Dim dtLastWorkDayOfPreviousFiscalYear As DateTime = New DateTime(2008, 6, 21).LastWorkDayOfPreviousFiscalYear
  '''   </code>
  '''   <code language="c#">
  '''     DateTime dtLastWorkDayOfPreviousFiscalYear = new DateTime(2008, 6, 21).LastWorkDayOfPreviousFiscalYear;
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function LastWorkDayOfPreviousFiscalYear(ByVal value As DateTime) As DateTime
    Select Case value.LastCalendarDayOfPreviousFiscalYear.DayOfWeek
      Case DayOfWeek.Sunday
        Return value.LastCalendarDayOfPreviousFiscalYear.Subtract(New TimeSpan(2, 0, 0, 0))
      Case DayOfWeek.Saturday
        Return value.LastCalendarDayOfPreviousFiscalYear.Subtract(New TimeSpan(1, 0, 0, 0))
      Case Else
        Return value.LastCalendarDayOfPreviousFiscalYear
    End Select
  End Function

  ''' <summary>
  ''' Formats the specified date as a properly DOD formatted <see cref="String">String</see>.
  ''' </summary>
  ''' <param name="value">The date to evaluate.</param>
  ''' <param name="includeTime">If set to <c>True</c> the time will be included in the formatted <see cref="String">String</see>.</param>
  ''' <returns>A date formatted as dd-MMM-yyyy HH:mm:ss.</returns>
  ''' <example>
  '''   <para>The following examples display a message displaying the specified date in the DOD standard format.  The displayed values will be '21-JUN-2008' and '21-JUN-2008 21:30:10'.</para>
  '''   <code language="vb">
  '''     MsgBox(New DateTime(2008, 6, 21).ToDODString(False))
  '''     MsgBox(New DateTime(2008, 6, 21, 21, 30, 10).ToDODString(True))
  '''   </code>
  '''   <code language="c#">
  '''     MsgBox(new DateTime(2008, 6, 21).ToDODString(false));
  '''     MsgBox(new DateTime(2008, 6, 21, 21, 30, 10).ToDODString(true));
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function ToDODString(ByVal value As DateTime, _
                                            ByVal includeTime As Boolean) As String
    If includeTime = True Then
      Return Format(value, "dd-MMM-yyyy HH:mm:ss").ToUpper
    Else
      Return Format(value, "dd-MMM-yyyy").ToUpper
    End If
  End Function

  ''' <summary>
  ''' Gets the age of the <see cref="DateTime">DateTime</see> value.
  ''' </summary>
  ''' <param name="value">The value to evaluate.</param>
  ''' <returns>The age of the value</returns>
  ''' <remarks>If the specified value is after the current date, the method will return 0.</remarks>
  ''' <example>
  '''   <para>The following examples display a message displaying the age of the specified date.  Assuming the current date is June 21, 2008, the displayed value will be 2.</para>
  '''   <code language="vb">
  '''     MsgBox(New DateTime(2008, 6, 21).Age)
  '''   </code>
  '''   <code language="c#">
  '''     MsgBox(new DateTime(2008, 6, 21).Age);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function Age(ByVal value As DateTime) As Short
    If value <= Now Then
      If value.Month < Now.Month Then
        Return Convert.ToInt16(DateDiff(DateInterval.Year, value, Now))
      ElseIf value.Month = Now.Month Then
        If value.Day <= Now.Day Then
          Return Convert.ToInt16(DateDiff(DateInterval.Year, value, Now))
        Else
          Return Convert.ToInt16(DateDiff(DateInterval.Year, value, Now) - 1)
        End If
      Else
        Return Convert.ToInt16(DateDiff(DateInterval.Year, value, Now) - 1)
      End If
    Else
      Return 0
    End If
  End Function

  ''' <summary>
  ''' Gets the age of the <see cref="DateTime">DateTime</see> value.
  ''' </summary>
  ''' <param name="value">The value to evaluate.</param>
  ''' <returns>The age of the value</returns>
  ''' <remarks>If the specified value is after the current date, the method will return a negative number.</remarks>
  ''' <example>
  '''   <para>The following examples display a message displaying the age of the specified date.  Assuming the current date is June 21, 2008, the displayed value will be 2.</para>
  '''   <code language="vb">
  '''     MsgBox(New DateTime(2008, 6, 21).Age)
  '''   </code>
  '''   <code language="c#">
  '''     MsgBox(new DateTime(2008, 6, 21).Age);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function Age2(ByVal value As DateTime) As Short
    If value.Month < Now.Month Then
      Return Convert.ToInt16(DateDiff(DateInterval.Year, value, Now))
    ElseIf value.Month = Now.Month Then
      If value.Day <= Now.Day Then
        Return Convert.ToInt16(DateDiff(DateInterval.Year, value, Now))
      Else
        Return Convert.ToInt16(DateDiff(DateInterval.Year, value, Now) - 1)
      End If
    Else
      Return Convert.ToInt16(DateDiff(DateInterval.Year, value, Now) - 1)
    End If
  End Function

  ''' <summary>
  ''' Gets the number of days since the specified date.
  ''' </summary>
  ''' <param name="value">The date to compute.</param>
  ''' <returns>The number of days since the specified date.</returns>
  ''' <example>
  '''   <para>The following examples display a message displaying the number of days since the specified date.  Assuming the current date is June 21, 2008, the displayed value will be 10.</para>
  '''   <code language="vb">
  '''     MsgBox(New DateTime(2008, 6, 11).DaysSince)
  '''   </code>
  '''   <code language="c#">
  '''     MsgBox(new DateTime(2008, 6, 11).DaysSince);
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function DaysSince(ByVal value As DateTime) As Integer
    Return DateTime.Now.Subtract(value).Days
  End Function

End Module